import Vue from 'vue'
import Router from 'vue-router'
import ManagerIndex from './pages/ManagerIndex'
import ConsumerIndex from './pages/ConsumerIndex'
import Download from './components/Download'
import Upload from './components/Upload'
import PersonAdd from './components/PersonAdd'
import PhotoShow from './components/PhotoShow'
import PersonBrowser from './components/PersonBrowser'
import StudentScore from './components/StudentScore'
import Login from './pages/Login'
import Reg from './pages/Reg';
import Welcome from './components/Welcome'
import ApplyLeave from './components/ApplyLeave.vue';
import AuditLeave from './components/AuditLeave.vue';
import { Message } from 'element-ui'


Vue.use(Router);
//一般用户使用界面
let consumerRoutes = {
    path: '/consumer',
    name: 'consumer',
    redirect: '/consumer/download',
    component: ConsumerIndex,
    description: '用户页面',
    children: [{
            path: 'download',
            name: 'download',
            component: Download,
            description: '文件下载',
            groupIndex: 1,
        },
        {
            path: 'upload',
            name: 'upload',
            component: Upload,
            description: '文件上传',
            groupIndex: 2,
        },
        {
            path: 'personAdd',
            name: 'personAdd',
            component: PersonAdd,
            description: '提交表单',
            groupIndex: 3,
        },
        {
            path: 'personBrowser',
            name: 'personBrowser',
            component: PersonBrowser,
            description: '新增浏览',
            groupIndex: 4,
        },
        {
            path: 'studentScore',
            name: 'studentScore',
            component: StudentScore,
            description: '学生分数',
            groupIndex: 5,
        },
        {
            path: 'photoShow',
            name: 'photoShow',
            component: PhotoShow,
            description: '图片显示',
            groupIndex: 9,
        },
    ]

    /*        {
                path: 'download',
                name: 'download',
                component:()=> import('./views/business/Download.vue'),
                description: '文件下载',
                groupIndex: 1,
            },*/

};
export { consumerRoutes };
//后台管理页面
let managerRoutes = {
    path: '/manager',
    name: 'manager',
    redirect: '/manager/welcome',
    component: ManagerIndex,
    description: '管理页面',
    children: [{
            path: 'welcome',
            name: 'welcome',
            component: Welcome,
            description: '首面板',
            groupIndex: 1,
        },
        {
            path: 'applyLeave',
            name: 'applyLeave',
            component: ApplyLeave,
            description: '请假申请',
            groupIndex: 2,
        },
        {
            path: 'auditLeave',
            name: 'auditLeave',
            component: AuditLeave,
            description: '请假审核',
            groupIndex: 3,
        },
    ]

};
export { managerRoutes };

let menuRoutes = [
    consumerRoutes,
    managerRoutes,
];
export { menuRoutes };
// let hideRoutes=[];


let loginRoutes = {
    path: '/login',
    name: 'login',
    component: Login,
    description: '登录主页面',
};
let regRoutes = {
    path: '/reg',
    name: 'reg',
    component: Reg,
    description: '注册页面',
};
let router = new Router({
    routes: [
        consumerRoutes,
        managerRoutes,
        loginRoutes,
        regRoutes,
        {
            path: '/',
            name: 'index',
            redirect: '/login',
        }
    ]
});
/*function getCookieValue(keyword){
    var listString = document.cookie.split("; ");
    for (let i = 0; i <listString.length ; i++) {
        let point = listString.split('=');
        if (point[0]==keyword){
            return point[1];
        }
        return null;

    }
}*/
router.beforeEach((to, from, next) => {


    let auth = router.app.$options.store.state.auth;
    if (!auth) {
        Message.warning({ message: "auth存在于store?：" + auth })
        if (to.path !== '/login' && to.path !== '/reg') {
            //如果不是登录页面不是注册页面就跳转拦截
            Message.warning({ message: "topath：" + to.path })
            next({
                path: '/login'
            })
        } else {
            next()
        }


    } else {
        // Message.warning({ message: "auth存在　：" + auth })
        console.log({ message: "auth存在　：" + auth })
        next()
    }


    // if (getCookieValue('JSESSIONID')===null){
    //     next({
    //         path:'/'
    //     })
    // }
    // console.log(getCookieValue('JSESSIONID'));
    // next();
});

export default router;